package umls.expander;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class ExpandedConcept {
	private String ECUI;
	private String SourceCUI;
	private Set<String> ECUIPreferredTerms;
	private String SourceCUITerm;
	private ArrayList<Relation> Relations;
	private TreeMap<String, SemanticType> SemanticTypes;

	public ExpandedConcept() {
		ECUI = "";
		SourceCUI = "";
		ECUIPreferredTerms = new HashSet<String>();
		SourceCUITerm = "";
		Relations = new ArrayList<Relation>();
		SemanticTypes = new TreeMap<String, SemanticType>();
	}

	public void SetECui(String ECUI) {
		this.ECUI = ECUI;
	}

	public void SetSourceCUI(String SourceCUI) {
		this.SourceCUI = SourceCUI;
	}

	public void SetSourceCUITerm(String SourceCUITerm) {
		this.SourceCUITerm = SourceCUITerm;
	}

	public String GetECUI() {
		return this.ECUI;
	}

	public String GetSourceCUI() {
		return this.SourceCUI;
	}

	public ArrayList<String> GetECUIPreferredTermsAsArrayList() {
		ArrayList<String> result = new ArrayList<String>();

		Iterator itr = this.ECUIPreferredTerms.iterator();
		while (itr.hasNext()) {
			result.add((String) itr.next());
		}

		return result;
	}

	public ArrayList<String> GetTUIArrayList() {
		ArrayList<String> result = new ArrayList<String>();

		Set semtypeset = this.SemanticTypes.entrySet();

		Iterator semtypeset_it = semtypeset.iterator();

		while (semtypeset_it.hasNext()) {
			Map.Entry<String, SemanticType> semtype = (Map.Entry<String, SemanticType>) semtypeset_it
					.next();

			result.add(semtype.getValue().GetTUI());
		}

		return result;
	}

	public Iterator<String> iterator() {
		return this.ECUIPreferredTerms.iterator();
	}

	public String GetSourceCUITerm() {
		return this.SourceCUITerm;
	}

	public void AddPreferredTerm(String preferredTerm) {
		this.ECUIPreferredTerms.add(preferredTerm);
	}

	public String PrintPreferredTermsAsString() {
		StringBuilder result = new StringBuilder();
		String NEW_LINE = System.getProperty("line.separator");

		Iterator itr = this.ECUIPreferredTerms.iterator();
		while (itr.hasNext()) {
			result.append("\t\t" + itr.next() + NEW_LINE);
		}

		return result.toString();
	}

	public void AddRelation(Relation r) {
		this.Relations.add(r);
	}

	public void AddRelation(String rel, String rela) {
		Relation r = new Relation(rel, rela);

		this.Relations.add(r);
	}

	public String PrintRelationsAsString() {
		StringBuilder result = new StringBuilder();
		String NEW_LINE = System.getProperty("line.separator");

		Iterator<Relation> relations_it = this.Relations.iterator();

		while (relations_it.hasNext()) {
			Relation r = relations_it.next();
			result.append("\t\t" + r.GetRel() + " " + r.GetRela() + NEW_LINE);
		}

		return result.toString();
	}

	public void AddSemanticType(SemanticType semantictype) {
		this.SemanticTypes.put(semantictype.GetTUI(), semantictype);
	}

	public void AddSemanticType(String tui, String sty) {
		SemanticType semtype = new SemanticType(tui, sty);

		this.SemanticTypes.put(tui, semtype);
	}

	public String PrintSemanticTypesAsString() {
		StringBuilder result = new StringBuilder();
		String NEW_LINE = System.getProperty("line.separator");

		Iterator<String> semkey_itr = this.SemanticTypes.keySet().iterator();
		while (semkey_itr.hasNext()) {
			SemanticType semtype = this.SemanticTypes.get(semkey_itr.next());
			result.append("\t\t" + semtype.GetTUI() + " " + semtype.GetSTY()
					+ NEW_LINE);
		}

		return result.toString();
	}
}
